package service;

import java.util.List;

import util.RegexUtil;
import dao.ActorDAO;
import dao.ActorJobDAO;
import dao.CrewJobDAO;
import dao.UserDAO;
import domain.Actor;
import domain.ActorJob;
import domain.CrewJob;
import domain.Movie;
import domain.User;
import ex.AuthenticationFailedException;
import ex.DatabaseException;
import ex.ProjectCompositionFailedException;
import ex.RegistrationFailedException;

public class JobService {

	ActorJobDAO actorJobDao = new ActorJobDAO();
	CrewJobDAO crewJobDao = new CrewJobDAO();

	public void createActorJob(ActorJob actorJob) throws DatabaseException,
			ProjectCompositionFailedException {
		if (actorJob != null) {
			actorJobDao.insertActorJob(actorJob);
		} else {
			throw new ProjectCompositionFailedException(
					"Project composition succeded but actor definition is not. Please add it later on! ");
		}
	}

	public void createCrewJob(CrewJob crewJob) throws DatabaseException,
			ProjectCompositionFailedException {
		if (crewJob != null) {
			crewJobDao.insertCrewJob(crewJob);
		} else {
			throw new ProjectCompositionFailedException(
					"Project composition succeded but crew definition is not. Please add it later on! ");
		}
	}

	public List<ActorJob> getActorJobsByMovie(Movie movie)
			throws DatabaseException, ProjectCompositionFailedException {
		if (movie != null) {
			return actorJobDao.selectActorJobByMid(movie.getMid());
		} else {
			throw new ProjectCompositionFailedException(
					"Project composition succeded but actor definition is not. Please add it later on! ");
		}
	}

	public ActorJob getActorJobByAjid(long ajid) throws DatabaseException {
		return actorJobDao.selectActorJobByAjid(ajid);
	}

	public List<CrewJob> getCrewJobsByMovie(Movie movie)
			throws DatabaseException, ProjectCompositionFailedException {
		if (movie != null) {
			return crewJobDao.selectCrewJobByMid(movie.getMid());
		} else {
			throw new ProjectCompositionFailedException(
					"Project composition succeded but actor definition is not. Please add it later on! ");
		}
	}

	public CrewJob getCrewJobByCjid(long cjid) throws DatabaseException {
		return crewJobDao.selectCrewJobByCjid(cjid);
	}

	public void updateCrewJob(CrewJob cj) throws DatabaseException {
		crewJobDao.editCrewJob(cj);
	}

	public void updateActorJob(ActorJob aj) throws DatabaseException {
		actorJobDao.editActorJob(aj);
	}

	public void removeActorJob(ActorJob actorJob) throws DatabaseException {
		actorJobDao.deleteActorJob(actorJob.getAjid());
	}

	public void removeCrewJob(CrewJob crewJob) throws DatabaseException {
		crewJobDao.deleteCrewJob(crewJob.getCjid());
	}

}
